#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <unistd.h>
#include <sys/wait.h>

using namespace std;

int main(int argc, char *argv[]) 
{
    try
    {
        if (argc < 11) throw string("bad arguments\n");

        pid_t query1_pid, query2_pid, query3_pid, query4_pid;

        if ((query1_pid = fork()) == 0) 
        {
            execl("./src/query1", "", argv[1], argv[2], argv[3], argv[4], (char *)0);
        }

        if ((query2_pid = fork()) == 0) 
        {
            execl("./src/query2", "", argv[1], argv[2], argv[5], argv[6], (char *)0);
        }

        if ((query3_pid = fork()) == 0) 
        {
            execl("./src/query3", "", argv[1], argv[2], argv[7], argv[8], (char *)0);
        }
    
        if ((query4_pid = fork()) == 0) 
        {
            execl("./src/query4", "", argv[1], argv[2], argv[9], argv[10], (char *)0);
        }

        waitpid(query1_pid, NULL, 0);
        waitpid(query2_pid, NULL, 0);
        waitpid(query3_pid, NULL, 0);
        waitpid(query4_pid, NULL, 0);
    }
    catch (const string &err)
    {
        fprintf(stderr, "%s", err.c_str());
    }
    catch (...)
    {
        fprintf(stderr, "uncaught error\n");
    }

    return 0;
}
